﻿#include <iostream>
#include <vector>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <string>
#include <set>
#include <forward_list>
#include <map>
#include <list>
#include <deque>
#include <tuple>
#include <cassert>
#include <thread>
#include <random>
#include <stdlib.h>

using namespace std;
namespace Project01
{
	void Print(const int& val)
	{
		cout << val << endl;
	}
	void Test01()
	{
		std::thread t(Print,1);
		cout << "thread run" << endl;
		t.join();
	}

	struct TestData
	{
		TestData(int val):a(val) {
			cout << "Init" << endl;
		}

		~TestData() {
			cout << "~TestData" << endl;
		}

		int a = 0;
	};
	
	void Test03(const std::shared_ptr<TestData>& ptr)
	{
		cout << "2:" << ptr.use_count() << endl;	//1
		std::shared_ptr<TestData> ptr1 = ptr;
		cout << "3:" << ptr.use_count() << endl;	//2
		cout << "5:" << ptr1.use_count() << endl;	//2
	}

	void Test04(std::shared_ptr<TestData> ptr)
	{
		cout << "2:" << ptr.use_count() << endl;	//2
		std::shared_ptr<TestData> ptr1 = ptr;
		cout << "3:" << ptr.use_count() << endl;	//3
		cout << "5:" << ptr1.use_count() << endl;	//3
	}

	void Test05()
	{

	}

	void Test02() 
	{
		std::shared_ptr<TestData> ptr = std::make_shared<TestData>(10);
		cout <<"1:"<< ptr.use_count() << endl;	//1
		//Test03(ptr);
		//Test04(ptr);
		//cout << "4:" << ptr.use_count() << endl;	//1

		//std::shared_ptr<TestData> ptr1(ptr.get());		//禁止一份数据使用两个指针托管
	}
};

namespace Project02
{
	void Test01()
	{
		uint32_t threadCount = std::thread::hardware_concurrency();
		cout << "hardware_concurrency:" << threadCount << endl;

		std::tuple<int, int, int> tp = std::make_tuple<int, int, int>(1, 1, 1);


	}


	void Test02()
	{
		std::vector<int> vData;
		for (int i = 0; i < 20; ++i)
		{
			vData.emplace_back(i);
		}

		for (auto it = vData.begin(); it != vData.end();)
		{
			if (*it == 15)
			{
				it = vData.erase(it);
			}
			else
			{
				it = vData.erase(it);
			}
		}
	}

	struct Perons
	{
		Perons(int val) :i(val) {

		}

		int i = 0;
	};


	void Test03()
	{
		std::vector<Perons> vData;
		for (auto i = 0; i < 20;++i)
		{
			vData.emplace_back(i);
		}


		int nVal = 0;



		std::find_if(vData.begin(), vData.end(),
			[&](Perons& person)
		{
			if (person.i % 2 != 0)
				return false;

			if (person.i == 10)
			{
				nVal = person.i;
				return true;
			}
			return false;
		}
		);
	}




};

namespace Project03
{















};





int main()
{
	
	system("pause");
	return 0;
}

